import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
import javax.swing.UIManager;
import java.awt.Font;
import java.util.LinkedList;

import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JList;
import javax.swing.JComboBox;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.xml.ws.handler.MessageContext;
import javax.swing.ImageIcon;
import javax.swing.JScrollBar;
import javax.swing.JSlider;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.JInternalFrame;
import javax.swing.JDesktopPane;
import java.awt.Color;
import java.awt.Frame;
import java.awt.GridLayout;

public class Launch {

	private JFrame frame;
	private JTextField textAlliance;
	private JTextField textInbound;
	private JTextField textOutbound;
	private JTextField textSTA;
	private JTextField textSTD;
	private JTextField textACtype;
	private JTextField textPaxIn;
	private JTextField textPaxOut;
	private JTextField textPassport;
	private JTextField textCarousel;
	private JTextField textCustoms;
	public static LinkedList<Flight> FlightList = new LinkedList<Flight>();
	public static LinkedList<PassportUnit> PassportList = new LinkedList<PassportUnit>();
	public static LinkedList<CustomUnit> CustomsList = new LinkedList<CustomUnit>();
	public static LinkedList<BaggageCarousel> CarouselList = new LinkedList<BaggageCarousel>();
	public static LinkedList<JTextField> textlist = new LinkedList<JTextField>();
	public static JPanel schedulePanel = new JPanel();
	public static LinkedList<JTextArea> textArea1 = new LinkedList<JTextArea>();
	public static LinkedList<JTextArea> textArea2 = new LinkedList<JTextArea>();
	public static LinkedList<JTextArea> textArea3 = new LinkedList<JTextArea>();

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Launch window = new Launch();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public Launch() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */

	private void initialize() {

		Flight f1 = new Flight("Star Alliance", "Flight 1 IN", "Flight 1 OUT",
				0100, 0500, "Boeing 777", 50, 150, 1, 1, 2011);
		Flight f2 = new Flight("Star Alliance", "Flight 2 IN", "Flight 2 OUT",
				0110, 0500, "Boeing 777", 100, 150, 1, 1, 2011);
		Flight f3 = new Flight("Star Alliance", "Flight 3 IN", "Flight 3 OUT",
				0120, 0500, "Boeing 777", 200, 150, 1, 1, 2011);

		Flight f4 = new Flight("Star Alliance", "Flight 4 IN", "Flight 4 OUT",
				0400, 0500, "Boeing 777", 200, 150, 1, 1, 2011);

		Flight f5 = new Flight("Star Alliance", "Flight 5 IN", "Flight 5 OUT",
				0700, 0500, "Boeing 777", 200, 150, 1, 1, 2011);

		Flight f6 = new Flight("Star Alliance", "Flight 6 IN", "Flight 5 OUT",
				0400, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f7 = new Flight("Star Alliance", "Flight 7 IN", "Flight 5 OUT",
				0700, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f8 = new Flight("Star Alliance", "Flight 8 IN", "Flight 5 OUT",
				0700, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f9 = new Flight("Star Alliance", "Flight 9 IN", "Flight 5 OUT",
				1000, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f10 = new Flight("Star Alliance", "Flight 10 IN",
				"Flight 5 OUT", 1000, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		
		
		
		
		Flight f11 = new Flight("Star Alliance", "Flight 11 IN",
				"Flight 5 OUT", 1015, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f12 = new Flight("Star Alliance", "Flight 12 IN",
				"Flight 5 OUT", 1445, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f13 = new Flight("Star Alliance", "Flight 13 IN",
				"Flight 5 OUT", 1900, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f14 = new Flight("Star Alliance", "Flight 14 IN",
				"Flight 5 OUT", 2130, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f15 = new Flight("Star Alliance", "Flight 15 IN",
				"Flight 5 OUT", 0730, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f16 = new Flight("Star Alliance", "Flight 16 IN",
				"Flight 5 OUT", 2330, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f17 = new Flight("Star Alliance", "Flight 17 IN",
				"Flight 5 OUT", 1400, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f18 = new Flight("Star Alliance", "Flight 18 IN",
				"Flight 5 OUT", 1201, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f19 = new Flight("Star Alliance", "Flight 19 IN",
				"Flight 5 OUT", 0255, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f20 = new Flight("Star Alliance", "Flight 20 IN",
				"Flight 5 OUT", 1600, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f21 = new Flight("Star Alliance", "Flight 21 IN",
				"Flight 5 OUT", 1255, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		
		Flight f22 = new Flight("Star Alliance", "Flight 22 IN",
				"Flight 5 OUT", 0730, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
				
		Flight f23 = new Flight("Star Alliance", "Flight 23 IN",
				"Flight 5 OUT", 1100, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f24 = new Flight("Star Alliance", "Flight 24 IN",
				"Flight 5 OUT", 1615, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f25 = new Flight("Star Alliance", "Flight 25 IN",
				"Flight 5 OUT", 1700, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f26 = new Flight("Star Alliance", "Flight 26 IN",
				"Flight 5 OUT", 1830, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f27 = new Flight("Star Alliance", "Flight 27 IN",
				"Flight 5 OUT", 2125, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f28 = new Flight("Star Alliance", "Flight 28 IN",
				"Flight 5 OUT", 1530, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f29 = new Flight("Star Alliance", "Flight 29 IN",
				"Flight 5 OUT", 1725, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f30 = new Flight("Star Alliance", "Flight 30 IN",
				"Flight 5 OUT", 1055, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f31 = new Flight("Star Alliance", "Flight 31 IN",
				"Flight 5 OUT", 1610, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f32 = new Flight("Star Alliance", "Flight 32 IN",
				"Flight 5 OUT", 1150, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		Flight f33 = new Flight("Star Alliance", "Flight 33 IN",
				"Flight 5 OUT", 1700, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f34 = new Flight("Star Alliance", "Flight 34 IN",
				"Flight 5 OUT", 2330, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f35 = new Flight("Star Alliance", "Flight 35 IN",
				"Flight 5 OUT", 1130, 0500, "Boeing 777", 200, 150, 1, 1, 2012);
		Flight f36 = new Flight("Star Alliance", "Flight 36 IN",
				"Flight 5 OUT", 1955, 0500, "Boeing 777", 200, 150, 1, 1, 2012);

		
		FlightList.add(f1);
		FlightList.add(f2);
		FlightList.add(f3);
		//FlightList.add(f4);
		//FlightList.add(f5);
		FlightList.add(f6);
		FlightList.add(f7);
		FlightList.add(f8);
		FlightList.add(f9);
		FlightList.add(f10);
		FlightList.add(f11);
		FlightList.add(f12);
		FlightList.add(f13);
		FlightList.add(f14);
		FlightList.add(f15);
		FlightList.add(f16);
		FlightList.add(f17);
		FlightList.add(f18);
		FlightList.add(f19);
		FlightList.add(f20);
		FlightList.add(f21);
		FlightList.add(f22);
		FlightList.add(f23);
		FlightList.add(f24);
		FlightList.add(f25);
		FlightList.add(f26);
		FlightList.add(f27);
		FlightList.add(f28);
		FlightList.add(f29);
		FlightList.add(f30);
		FlightList.add(f31);
		FlightList.add(f32);
		FlightList.add(f33);
		FlightList.add(f34);
		FlightList.add(f35);
		FlightList.add(f36);


		frame = new JFrame();
		frame.setBounds(100, 100, 1067, 634);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		
				schedulePanel.setBounds(784, 52, 267, 520);
				schedulePanel.setLayout(new GridLayout(10, 1, 0, 0));
				schedulePanel.add(new JLabel("Flight Panel"));
				schedulePanel.setVisible(false);
				
						frame.getContentPane().add(schedulePanel);

		final JPanel runPanel = new JPanel();
		runPanel.setBounds(416, 63, 358, 509);
		frame.getContentPane().add(runPanel);
		runPanel.setLayout(null);
		runPanel.setVisible(false);

		final JPanel simpanel = new JPanel();
		simpanel.setBounds(0, 52, 774, 551);
		simpanel.setLayout(new GridLayout(5, 1000, 0, 0));

		frame.getContentPane().add(simpanel);
		
		
		simpanel.setVisible(false);

		final JPanel terminalSettingPanel = new JPanel();
		terminalSettingPanel.setBounds(0, 146, 387, 457);
		frame.getContentPane().add(terminalSettingPanel);
		terminalSettingPanel.setLayout(null);
		terminalSettingPanel.setVisible(false);

		final JButton buttonStart = new JButton("Start");
		buttonStart.setBounds(256, 420, 121, 25);
		terminalSettingPanel.add(buttonStart);

		buttonStart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				terminalSettingPanel.setVisible(false);
				runPanel.setVisible(true);

			}
		});
		buttonStart.setEnabled(false);

		final JButton addFlightButton = new JButton("Add Flight");
		final JPanel addFlightPanel = new JPanel();
		addFlightPanel.setBounds(416, 63, 358, 281);
		frame.getContentPane().add(addFlightPanel);
		addFlightPanel.setLayout(null);
		addFlightPanel.setVisible(false);
		addFlightButton
				.setToolTipText("Will schedule a flight on a specific date");
		addFlightButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				terminalSettingPanel.setVisible(false);
				addFlightPanel.setVisible(true);
			}
		});
		addFlightButton.setBounds(28, 78, 89, 23);
		frame.getContentPane().add(addFlightButton);

		final JButton terminalSettings = new JButton("Terminal Settings");

		terminalSettings.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				addFlightPanel.setVisible(false);
				terminalSettingPanel.setVisible(true);
			}
		});
		terminalSettings.setBounds(28, 112, 162, 23);
		frame.getContentPane().add(terminalSettings);
		
				final JButton Restart = new JButton("Restart");
				Restart.setBounds(550, 490, 50, 50);
				Restart.setVisible(false);
				frame.getContentPane().add(Restart);
				Restart.addActionListener(new ActionListener() {
						
						@SuppressWarnings("deprecation")
						@Override
						public void actionPerformed(ActionEvent arg0) {
							for(int i =0; i< PassportList.size();i++)
							PassportList.get(i).stop();
							for(int i=0 ;i<CarouselList.size();i++)
							CarouselList.get(i).stop();
							for(int i=0;i<CustomsList.size();i++)
							CustomsList.get(i).stop();
						for(int i = 0; i<FlightList.size();i++)
							FlightList.get(i).stop();
							
							runPanel.setVisible(false);
							simpanel.setVisible(false);
							terminalSettingPanel.setVisible(false);
							addFlightPanel.setVisible(false);
							schedulePanel.setVisible(false);
							
							addFlightButton.setVisible(true);
							terminalSettings.setVisible(true);

							
						}
					});

		JLabel lblNewLabel = new JLabel(
				"Terminal 2 Building Simulation Tool (Arrival Area)");
		lblNewLabel.setFont(new Font("Agency FB", Font.PLAIN, 30));
		lblNewLabel.setForeground(UIManager.getColor("Button.foreground"));
		lblNewLabel.setVerticalAlignment(SwingConstants.BOTTOM);
		lblNewLabel.setBounds(197, 11, 452, 41);
		frame.getContentPane().add(lblNewLabel);

		JLabel lblNewLabel_1 = new JLabel("Developed By:");
		lblNewLabel_1.setBounds(687, 712, 80, 14);
		frame.getContentPane().add(lblNewLabel_1);

		JLabel lblMichaelIbraam = new JLabel("Michael Ibraam");
		lblMichaelIbraam.setBounds(687, 725, 87, 14);
		frame.getContentPane().add(lblMichaelIbraam);

		final JComboBox dayList = new JComboBox();
		dayList.setToolTipText("Choose a day");
		dayList.setMaximumRowCount(31);
		for (int i = 1; i < 32; i++) {
			dayList.addItem("" + i);
		}
		dayList.setBounds(50, 11, 46, 20);
		addFlightPanel.add(dayList);

		JLabel dayLabel = new JLabel("Day :");
		dayLabel.setBounds(10, 14, 46, 14);
		addFlightPanel.add(dayLabel);

		JLabel lblMonth = new JLabel("Month : ");
		lblMonth.setBounds(103, 15, 46, 14);
		addFlightPanel.add(lblMonth);

		final JComboBox monthList = new JComboBox();
		for (int i = 1; i < 13; i++) {
			monthList.addItem("" + i);
		}

		monthList.setToolTipText("Choose a month");
		monthList.setMaximumRowCount(12);
		monthList.setBounds(156, 11, 46, 20);
		addFlightPanel.add(monthList);

		JLabel yearLabel = new JLabel("Year : ");
		yearLabel.setBounds(210, 14, 46, 14);
		addFlightPanel.add(yearLabel);

		final JComboBox yearList = new JComboBox();
		for (int i = 2011; i < 2021; i++) {
			yearList.addItem("" + i);
		}
		yearList.setToolTipText("Choose a year");
		yearList.setMaximumRowCount(31);
		yearList.setBounds(254, 11, 59, 20);
		addFlightPanel.add(yearList);

		JLabel labelAlliance = new JLabel("Alliance : ");
		labelAlliance.setBounds(10, 45, 61, 14);
		addFlightPanel.add(labelAlliance);

		textAlliance = new JTextField();
		textAlliance.setBounds(81, 42, 86, 20);
		addFlightPanel.add(textAlliance);
		textAlliance.setColumns(10);

		JLabel Inbound = new JLabel("Inbound : ");
		Inbound.setBounds(10, 70, 59, 14);
		addFlightPanel.add(Inbound);

		textInbound = new JTextField();
		textInbound.setColumns(10);
		textInbound.setBounds(81, 67, 86, 20);
		addFlightPanel.add(textInbound);

		JLabel Outbound = new JLabel("Outbound : ");
		Outbound.setBounds(10, 92, 72, 14);
		addFlightPanel.add(Outbound);

		textOutbound = new JTextField();
		textOutbound.setBounds(81, 90, 86, 20);
		addFlightPanel.add(textOutbound);
		textOutbound.setColumns(10);

		JLabel labelSTA = new JLabel("STA : ");
		labelSTA.setBounds(10, 116, 59, 14);
		addFlightPanel.add(labelSTA);

		textSTA = new JTextField();
		textSTA.setColumns(10);
		textSTA.setBounds(81, 113, 86, 20);
		addFlightPanel.add(textSTA);

		JLabel labelSTD = new JLabel("STD : ");
		labelSTD.setBounds(10, 141, 59, 14);
		addFlightPanel.add(labelSTD);

		textSTD = new JTextField();
		textSTD.setColumns(10);
		textSTD.setBounds(81, 138, 86, 20);
		addFlightPanel.add(textSTD);

		JLabel lblAcType = new JLabel("A/C type : ");
		lblAcType.setBounds(10, 166, 59, 14);
		addFlightPanel.add(lblAcType);

		textACtype = new JTextField();
		textACtype.setColumns(10);
		textACtype.setBounds(81, 163, 86, 20);
		addFlightPanel.add(textACtype);

		JLabel labelPaxIn = new JLabel("Pax In : ");
		labelPaxIn.setBounds(10, 194, 59, 14);
		addFlightPanel.add(labelPaxIn);

		textPaxIn = new JTextField();
		textPaxIn.setColumns(10);
		textPaxIn.setBounds(81, 188, 86, 20);
		addFlightPanel.add(textPaxIn);

		JLabel labelPaxOut = new JLabel("Pax Out : ");
		labelPaxOut.setBounds(10, 216, 59, 14);
		addFlightPanel.add(labelPaxOut);

		textPaxOut = new JTextField();
		textPaxOut.setColumns(10);
		textPaxOut.setBounds(81, 213, 86, 20);
		addFlightPanel.add(textPaxOut);
		final JOptionPane error = new JOptionPane();
		final JOptionPane Done = new JOptionPane();

		JButton addFlightSubmit = new JButton("Add Flight");
		addFlightSubmit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				
				
				
				Flight flight = new Flight(
						textAlliance.getText(),
						textInbound.getText(),
						textOutbound.getText(),
						Integer.parseInt(textSTA.getText()),
						Integer.parseInt(textSTD.getText()),
						textACtype.getText(),
						Integer.parseInt(textPaxIn.getText()),
						Integer.parseInt(textPaxOut.getText()),
						Integer.parseInt(dayList.getSelectedItem().toString()),
						Integer.parseInt(monthList.getSelectedItem().toString()),
						Integer.parseInt(yearList.getSelectedItem().toString()));

				if (FlightList.size() !=0) {
					boolean found = false;

					for(int i = 0 ; i<FlightList.size();i++){
						if (flight.Inbound
								.equalsIgnoreCase(FlightList.get(i).Inbound)
								&& flight.day == FlightList.get(i).day
								&& flight.month == FlightList.get(i).month
								&& flight.year == FlightList.get(i).year) 
						{
							JOptionPane.showMessageDialog(frame,
									"Flight already exist", "Error",
									JOptionPane.ERROR_MESSAGE);
								found = true;
							break;

						}
					}  
					
					if(!found){
							FlightList.add(flight);
							JOptionPane.showMessageDialog(frame,
									"Fligh has been added", "Complete",
									JOptionPane.INFORMATION_MESSAGE);
					}



				} 

			}
		});
		addFlightSubmit.setBounds(10, 241, 157, 34);
		addFlightPanel.add(addFlightSubmit);

		JLabel lblNumberOfPassport = new JLabel("Number of Passport Units : ");
		lblNumberOfPassport.setBounds(0, 14, 161, 14);
		terminalSettingPanel.add(lblNumberOfPassport);

		textPassport = new JTextField();
		textPassport.setBounds(185, 11, 86, 20);
		terminalSettingPanel.add(textPassport);
		textPassport.setColumns(10);

		JLabel lblAveragePassportDelay = new JLabel(
				"Average Passport Delay Time ");
		lblAveragePassportDelay.setBounds(0, 48, 192, 14);
		terminalSettingPanel.add(lblAveragePassportDelay);

		final JLabel l1 = new JLabel("New label");
		l1.setBounds(330, 38, 50, 25);
		terminalSettingPanel.add(l1);

		final JLabel l2 = new JLabel("New label 2");
		l2.setBounds(325, 98, 55, 25);
		terminalSettingPanel.add(l2);

		final JSlider customsSlider = new JSlider();
		customsSlider.setMaximum(60);
		customsSlider.setMajorTickSpacing(5);
		customsSlider.setMinorTickSpacing(1);
		customsSlider.setBounds(185, 98, 121, 20);

		customsSlider.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				// TODO Auto-generated method stub
				l2.setText(Integer.toString(customsSlider.getValue()));

			}
		});
		customsSlider.setValue(30);
		customsSlider.setSnapToTicks(true);
		terminalSettingPanel.add(customsSlider);

		final JSlider passportSlider = new JSlider();
		passportSlider.setMaximum(60);
		passportSlider.setMajorTickSpacing(5);
		passportSlider.setMinorTickSpacing(1);
		passportSlider.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				l1.setText(Integer.toString(passportSlider.getValue()));

			}
		});

		passportSlider.setValue(30);
		passportSlider.setSnapToTicks(true);
		passportSlider.setBounds(185, 42, 121, 20);
		terminalSettingPanel.add(passportSlider);

		JLabel lblNumberOfBaggage = new JLabel("Number of Baggage Carousel :");
		lblNumberOfBaggage.setBounds(0, 132, 175, 14);
		terminalSettingPanel.add(lblNumberOfBaggage);

		textCarousel = new JTextField();
		textCarousel.setBounds(185, 129, 121, 20);
		terminalSettingPanel.add(textCarousel);
		textCarousel.setColumns(10);

		final JPanel tempPanel = new JPanel();
		tempPanel.setBounds(0, 180, 317, 229);
		tempPanel.setLayout(null);
		terminalSettingPanel.add(tempPanel);

		JLabel lblNumberOfCustoms = new JLabel("Number of Customs Units : ");
		lblNumberOfCustoms.setBounds(0, 73, 161, 14);
		terminalSettingPanel.add(lblNumberOfCustoms);

		JLabel lblAverageCustomsDelay = new JLabel(
				"Average Customs Delay Time ");
		lblAverageCustomsDelay.setBounds(0, 97, 192, 14);
		terminalSettingPanel.add(lblAverageCustomsDelay);

		JButton buildTerminal = new JButton("Build Terminal");

		final JLabel l3 = new JLabel("New label 3");
		l3.setBounds(325, 153, 55, 25);
		terminalSettingPanel.add(l3);

		buildTerminal.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				for (int i = 0; i < Integer.parseInt(textPassport.getText()); i++) {
					PassportUnit passportunit = new PassportUnit(i + 1, Integer
							.parseInt(l1.getText()) * 1000);
					
					PassportList.add(passportunit);

				}
				for (int i = 0; i < Integer.parseInt(textCustoms.getText()); i++) {
					CustomUnit customsunit = new CustomUnit(i + 1, Integer
							.parseInt(l2.getText()) * 1000);
					CustomsList.add(customsunit);
				}
				for (int i = 0; i < Integer.parseInt(textCarousel.getText()); i++) {
					BaggageCarousel bag = new BaggageCarousel(i + 1, Integer
							.parseInt(textlist.get(i).getText()), Integer
							.parseInt(l3.getText()) * 1000);

					CarouselList.add(bag);
				}

				JOptionPane.showMessageDialog(frame,
						" Terminal has been built ! ");

				buttonStart.setEnabled(true);

			}

		});
		buildTerminal.setBounds(0, 420, 161, 32);
		terminalSettingPanel.add(buildTerminal);

		textCustoms = new JTextField();
		textCustoms.setColumns(10);
		textCustoms.setBounds(185, 67, 86, 20);
		terminalSettingPanel.add(textCustoms);

		final JSlider baggageslider = new JSlider();
		baggageslider.setMaximum(30);
		baggageslider.setValue(30);
		baggageslider.setSnapToTicks(true);
		baggageslider.setMajorTickSpacing(5);
		baggageslider.setMinorTickSpacing(1);
		baggageslider.setBounds(185, 98, 121, 20);
		baggageslider.setSnapToTicks(true);
		baggageslider.setBounds(185, 153, 121, 20);

		baggageslider.addChangeListener(new ChangeListener() {

			@Override
			public void stateChanged(ChangeEvent arg0) {
				// TODO Auto-generated method stub
				l3.setText(Integer.toString(baggageslider.getValue()));

			}
		});

		terminalSettingPanel.add(baggageslider);

		JLabel lblAverageCarouselTime = new JLabel("Average Carousel Time ");
		lblAverageCarouselTime.setBounds(0, 157, 175, 14);
		terminalSettingPanel.add(lblAverageCarouselTime);

		JLabel label = new JLabel("Day :");
		label.setBounds(10, 8, 34, 14);
		runPanel.add(label);

		final JComboBox dayList2 = new JComboBox();
		dayList2.setBounds(68, 5, 40, 20);
		dayList2.setMaximumRowCount(31);
		for (int i = 1; i < 32; i++) {
			dayList2.addItem("" + i);
		}
		dayList2.setToolTipText("Choose a day");
		dayList2.setMaximumRowCount(31);
		runPanel.add(dayList2);

		JLabel label_1 = new JLabel("Month : ");
		label_1.setBounds(118, 8, 46, 14);
		runPanel.add(label_1);

		final JComboBox monthList2 = new JComboBox();
		monthList2.setToolTipText("Choose a month");
		for (int i = 1; i < 13; i++) {
			monthList2.addItem("" + i);
		}
		monthList2.setMaximumRowCount(12);
		monthList2.setBounds(174, 5, 46, 20);
		runPanel.add(monthList2);

		JLabel label_2 = new JLabel("Year : ");
		label_2.setBounds(228, 8, 46, 14);
		runPanel.add(label_2);

		final JComboBox yearList2 = new JComboBox();
		for (int i = 2011; i < 2021; i++) {
			yearList2.addItem("" + i);
		}
		yearList2.setToolTipText("Choose a year");
		yearList2.setMaximumRowCount(31);
		yearList2.setBounds(266, 5, 59, 20);
		runPanel.add(yearList2);
		
		
		
		JButton buttonRun = new JButton("RUN");
		final LinkedList<Flight> tempFlightList = new LinkedList<Flight>();
		buttonRun.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				runPanel.setVisible(false);
				addFlightPanel.setVisible(false);
				simpanel.setVisible(true);
				Restart.setVisible(true);
				schedulePanel.setVisible(true);
				addFlightButton.setVisible(false);
				terminalSettings.setVisible(false);

				for (int i = 0; i < PassportList.size(); i++) {

					JTextArea t = new JTextArea();

					JPanel p = new JPanel();
					t.setEditable(false);
					t.setText("" + PassportList.get(i).id);

					p.setLayout(new GridLayout(3, 0, 0, 0));
					p.add(new JLabel("Passport Unit" + PassportList.get(i).id));
					p.add(t);
					simpanel.add(p);
					textArea1.add(t);

					// simpanel.add(new JButton(""+i));

				}

				for (int i = 0; i < CarouselList.size(); i++) {
					JTextArea t = new JTextArea();
					JPanel p = new JPanel();

					t.setEditable(false);

					t.setText("" + CarouselList.get(i).id);

					p.setLayout(new GridLayout(3, 0, 0, 0));
					p.add(new JLabel("Baggage Carousel "
							+ CarouselList.get(i).id));
					p.add(t);
					simpanel.add(p);
					textArea2.add(t);

				}

				for (int i = 0; i < CustomsList.size(); i++) {
					JTextArea t = new JTextArea();
					JPanel p = new JPanel();

					t.setEditable(false);

					t.setText("" + CustomsList.get(i).id);

					p.setLayout(new GridLayout(3, 0, 0, 0));
					p.add(new JLabel("Customs Unit " + CustomsList.get(i).id));
					p.add(t);
					simpanel.add(p);
					textArea3.add(t);

				}

				for (int i = 0; i < FlightList.size(); i++) {
					if (FlightList.get(i).day == Integer.parseInt(dayList2
							.getSelectedItem().toString())
							&& FlightList.get(i).month == Integer
									.parseInt(monthList2.getSelectedItem()
											.toString())
							&& FlightList.get(i).year == Integer
									.parseInt(yearList2.getSelectedItem()
											.toString()))

					{
						tempFlightList.add(FlightList.get(i));

					}
				}
				start(tempFlightList);

			}

		});

		buttonRun.setBounds(78, 35, 184, 35);
		runPanel.add(buttonRun);

		textCarousel.getDocument().addDocumentListener(new DocumentListener() {

			@Override
			public void removeUpdate(DocumentEvent arg0) {
				// TODO Auto-generated method stub
				tempPanel.removeAll();
				tempPanel.repaint();

			}

			@Override
			public void insertUpdate(DocumentEvent arg0) {
				// TODO Auto-generated method stub
				update();
			}

			@Override
			public void changedUpdate(DocumentEvent arg0) {
				// TODO Auto-generated method stub

			}

			public void update() {
				int x = 0;

				for (int i = 1; i < Integer.parseInt(textCarousel.getText()) + 1; i++) {

					JLabel tempLabel = new JLabel("Carousel " + i
							+ " Capacity ");
					tempLabel.setBounds(0, -74 + x, 233, 182);

					JTextField tempText = new JTextField();
					textlist.add(tempText);
					tempText.setBounds(150, 10 + x, 100, 20);
					x = x + 20;

					tempPanel.add(tempLabel);
					tempPanel.add(tempText);
					tempPanel.repaint();

					// terminalSettingPanel.add(tempLabel);

				}

			}
		});

	}

	public static void start(LinkedList<Flight> flightlist) {
		for (int i = 0; i < flightlist.size(); i++) {

			flightlist.get(i).start();

		}

	}
}
